/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#include "MkEvent/MkTimerPool.h"
#include "MkUtil/MkThread.h"
#include <gtest/gtest.h>

TEST(MkTimerPool, TimerPoolTest)
{
    CMkTimerPool TimerPool;
    Uint32 ErrorCode = NoneError;
    ErrorCode = TimerPool.Start();
    EXPECT_EQ(ErrorCode, NoneError);
    Uint32 nCount = TimerPool.GetTimerCount();
    CMkTimer *pFreeTimer = TimerPool.GetFreeTimer();
    EXPECT_NE(nullptr, pFreeTimer);
    ErrorCode = TimerPool.Stop();
    EXPECT_EQ(ErrorCode, NoneError);
}

TEST(MkTimerPool, TimerPoolTest2)
{
    CMkTimerPool TimerPool;
    Uint32 ErrorCode = NoneError;
    ErrorCode = TimerPool.Start(1);
    EXPECT_EQ(ErrorCode, NoneError);
    ErrorCode = TimerPool.Start(1);
    EXPECT_EQ(ErrorCode, NoneError);
    Uint32 nCount = TimerPool.GetTimerCount();
    EXPECT_EQ(1, nCount);
    CMkTimer *pFreeTimer = TimerPool.GetFreeTimer();
    EXPECT_NE(nullptr, pFreeTimer);
    CMkThread::ThreadSleep(1);  //wait timer thread started
    TimerPool.Stop();
}